﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ODataRegression.Framework.Core.Factories;
using ODataRegression.Framework.Core.MetaDataOM;
using ODataRegression.Framework.Core.Shared;
using ODataTestFrameworkCore.shared;
using System.Reflection;
namespace ODataRegression.Framework.Core.TestOM
{
   public sealed class ODataTestBatch
    {
       public List<ODataTest> TestList;
       //public string ServiceURL = null;
       ODataService service;
       //string serviceRoot;
      // string SvcFileName;
       //TestConfiguration testConfig;
       ODataServiceInformation serviceInfo;
       public ODataTestBatch(ODataServiceInformation serviceInfo)
       {
          // this.SvcFileName = svcFileName;
          // this.serviceRoot = serviceRoot;
           //this.testConfig = config;
           this.serviceInfo = serviceInfo;
           //serviceRoot = serviceInfo.ServiceURI;
          // SvcFileName = serviceInfo.ServiceBusinessName;
           TestList = new List<ODataTest>();
           //this.ServiceURL = serviceURL;

           service = new ODataService(serviceInfo);
           CreateTest();
       }

      void CreateTest()
      {
         
        
          //Test For Entities 
          foreach (ODataEntitySet EntitySet in service.EntitySetCollection)
          {
              if (serviceInfo.IncludeEntityCollectionInTest(EntitySet.CollectionName))
              {

                  Assembly executingAssembly = Assembly.GetExecutingAssembly();
                 
                  foreach (Type objType in executingAssembly.GetTypes())
                  {
                      if (objType.BaseType==typeof(ODataTestFactoryBase))
                      {
                          object[] initParams = { this.serviceInfo.ServiceURI, this.serviceInfo.ServiceBusinessName, EntitySet };
                          IODataTestFactory testFactoryObj = (IODataTestFactory)Activator.CreateInstance(objType, initParams);

                          TestList.AddRange(testFactoryObj.CreateTestList());    
                      }
                  }

                
              }  
          }
      }
    }
}

